<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>进货</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="./images/favicon.png" />

    <!-- <link href="./css/style.css" rel="stylesheet" /> -->

    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/jsgrid/jsgrid-theme.min.css" rel="stylesheet" />
    <link href="assets/css/lib/jsgrid/jsgrid.min.css" type="text/css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/helper.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">

    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.min.js"></script>
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>

    <script>
        //页面初始化时加载用户数据
        $(document).ready(function () {
            var requestObj = {};
            requestObj["requestService"] = "QueryAllUser";
            requestObj["requestMethod"] = "";
            requestObj["data"] = {};
            var requestJson = JSON.stringify(requestObj)
            $.ajax({
                type: "POST",
                url: "http://192.168.70.135:80/api/",
                async: false,
                contentType: "application/json",
                data: requestJson,
                success: function (msg) {
                    $.each(msg.data, function (k, v) {
                        $("#userSelect").append("<option value =\"" + v.userID + "\">" + v.userName + "</option>")
                    })
                }
            });
        })
    </script>

    <script>
        //未入库商品管理-选择仓库后加载分区号
        $(document).ready(function () {
            $("#userSelect").change(function () {
                var selectUser = $("#userSelect").val();
                if (selectUser == "nullSelect") {
                    $("#oneStockSubmitToJobList").attr("disabled", true);
                } else
                    $("#oneStockSubmitToJobList").attr("disabled", false);
            })
        })
    </script>

    <script>
        $(document).ready(function () {
            $("button#doCommodityInfoSearch").click(function () {
                var requestObj = {};
                requestObj["requestService"] = "QueryCommodityInfo";
                requestObj["requestMethod"] = "";
                var requestData = {};
                requestData["barCode"] = document.getElementById("barCode").value;
                requestObj["data"] = JSON.stringify(requestData);
                var requestJson = JSON.stringify(requestObj);
                $.ajax({
                    type: "POST",
                    url: "http://192.168.70.135:80/api/",
                    contentType: "application/json",
                    data: requestJson,
                    success: function (msg) {
                        $.each(msg.data, function (k, v) {
                            $("#" + k).val(v);
                        })
                    }
                });
            })
        })
    </script>

    <script>
        $(document).ready(function () {
            $("#oneStockSubmit").click(function () {
                var oneStockInfo = {};
                oneStockInfo["barCode"] = document.getElementById("barCode").value;
                oneStockInfo["batchNo"] = document.getElementById("batchNo").value;
                oneStockInfo["productName"] = document.getElementById("productName").value;
                oneStockInfo["stockAmount"] = document.getElementById("stockAmount").value;
                oneStockInfo["stockPrice"] = document.getElementById("stockPrice").value;
                oneStockInfo["productTime"] = " ";
                var timeRemain = "不存在";

                var productTime = document.getElementById("productTime").value;
                if (productTime !== null && productTime.length !== 0) {
                    var productTimeDate = new Date(Date.parse(productTime));
                    oneStockInfo["productTime"] = productTimeDate.getTime();
                    var dateNow = new Date();
                    var saveDate = document.getElementById("saveDate").value;
                    if (saveDate !== null && saveDate.length !== 0) {
                        timeRemain = (parseInt(saveDate) - parseInt((dateNow - productTimeDate) / 86400000)).toString();
                    }
                }
                oneStockInfo["timeRemain"] = timeRemain;
                window.db.clients.push(oneStockInfo);
                $("#jsGrid").jsGrid("loadData");
            })
        })
    </script>

    <script>
        function constructStockSubmitRequest() {
            var requestObj = {};
            requestObj["requestService"] = "DoOneStock";
            requestObj["requestMethod"] = "";
            requestObj["data"] = window.db.clients;
            return requestObj;
        }
    </script>

    <script>
        $(document).ready(function () {
            $("#stockListSubmit").click(function () {
                var requestObj = constructStockSubmitRequest();
                var requestJson = JSON.stringify(requestObj)
                $.ajax({
                    type: "POST",
                    url: "http://192.168.70.135:80/api/",
                    contentType: "application/json",
                    data: requestJson,
                    success: function (msg) {
                        alert("已成功执行入库请求");
                        location.reload();
                    }
                });
            })
        })
    </script>

    <script>
        $(document).ready(function () {
            $("#oneStockSubmitToJobList").click(function () {
                var requestObj = {};
                requestObj["requestService"] = "JobService";
                requestObj["requestMethod"] = "assignJob";
                var data = {};
                data["userID"] = $("#userSelect").val();
                data["jobDetail"] = JSON.stringify(constructStockSubmitRequest());
                requestObj["data"] = data;
                var requestJson = JSON.stringify(requestObj);
                $.ajax({
                    type: "POST",
                    url: "http://192.168.70.135:80/api/",
                    contentType: "application/json",
                    data: requestJson,
                    success: function (msg) {
                        alert("已成功加入任务队列");
                        location.reload();
                    }
                });
            })
        })
    </script>

    <script>
        $(document).ready(function () {
            $("#generateBatchNo").click(function () {
                var requestObj = {};
                requestObj["requestService"] = "GenerateBatchNo";
                requestObj["requestMethod"] = "";
                requestObj["data"] = "";
                var requestJson = JSON.stringify(requestObj)
                $.ajax({
                    type: "POST",
                    url: "http://192.168.70.135:80/api/",
                    contentType: "application/json",
                    data: requestJson,
                    success: function (msg) {
                        document.getElementById("batchNo").value = msg.data;
                    }
                })
            })
        })
    </script>
    <!-- <style>
        .jsgrid-grid-header {
            margin-right: -8px;
        }
    </style> -->
</head>

<body>

    <script src="./common.js"></script>

    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div id="main-content">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="card">
                                <div class="card-header">
                                    <div class="card-title">
                                        <h4>本次进货清单 </h4>
                                    </div>
                                </div>
                                <div class="card-body">
                                    <div class="jsgrid-table-panel">
                                        <div id="jsGrid"></div>
                                    </div>
                                    </br>
                                    <div class="row">
                                        <button type="button" class="btn btn-primary m-b-10 m-l-5"
                                            id="stockListSubmit">确认进货</button>
                                        <div class="col-lg-4">
                                            <select id="userSelect" type="dropdown" class="form-control">
                                                <option value="nullSelect">
                                                    选择一个用户</option>
                                            </select>
                                        </div>
                                        <button type="button" class="btn btn-primary m-b-10 m-l-5"
                                            id="oneStockSubmitToJobList" disabled="true">提交到任务列表</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="card">
                                <div class="card-header">
                                    <div class="card-title">
                                        <h4>下一件商品 </h4>
                                    </div>
                                </div>
                                <div class="card-body">
                                    <div class="basic-form">
                                        <form>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>商品条码</label>
                                                        <input id="barCode" type="text" class="form-control">
                                                        <br />
                                                        <button type="button" class="btn btn-info m-b-10 m-l-5"
                                                            id="doCommodityInfoSearch">查询</button>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>商品名称</label>
                                                        <input id="productName" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>保质期（日）</label>
                                                        <input id="saveDate" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>生产日期（年/月/日）</label>
                                                        <div class="input-group date" id="productTimePicker">
                                                            <input id="productTime" type="text" class="form-control">
                                                            <span class="input-group-addon">
                                                                <span class="glyphicon glyphicon-calendar"></span>
                                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>规格型号</label>
                                                        <input id="type" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>关键字</label>
                                                        <input id="keyWord" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>简短描述</label>
                                                        <input id="description" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>厂家名称</label>
                                                        <input id="manufacturerName" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>厂家地址</label>
                                                        <input id="manufacturerAddress" type="text"
                                                            class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>企业社会信用代码</label>
                                                        <input id="firmCode" type="text" class="form-control">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>UNSPSC分类码</label>
                                                        <input id="categoryCode" type="text" class="form-control">
                                                    </div>
                                                </div>
                                            </div>
                                            <button type="button" class="btn btn-primary m-b-10 m-l-5"
                                                disabled="true">应用更改</button>
                                        </form>
                                        <hr />
                                        <form>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <label>批次号</label>
                                                        <input id="batchNo" type="text" class="form-control">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">


                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <button type="button" class="btn btn-info m-b-10 m-l-5"
                                                            id="generateBatchNo">生成批次号</button>&nbsp;&nbsp;
                                                    </div>
                                                </div>

                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <input type="checkbox" id="autoGenBatchNo">&nbsp;&nbsp;<label
                                                            for="autoGenBatchNo">自动生成批次号</label>
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <div class="form-group">
                                                        <label>进货数量（件）</label>
                                                        <input id="stockAmount" type="text" class="form-control">
                                                    </div>
                                                </div>
                                            </div>
                                    </div>
                                    <hr />
                                    <div class="row">
                                        <div class="col-lg-4">
                                            <div class="form-group">
                                                <label>进货价格（每件）</label>
                                                <input id="stockPrice" type="text" class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-lg-4">
                                            <div class="form-group">
                                                <label>进货价格（总计）</label>
                                                <input id="stockPriceSum" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox">&nbsp;&nbsp;&nbsp;提交时自动应用商品信息修改
                                        </label>
                                    </div>

                                    <button type="button" class="btn btn-primary m-b-10 m-l-5"
                                        id="oneStockSubmit">提交</button>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="footer">
                            <div class="copyright">
                                <p>Copyright © Designed &amp; Developed by <a href="#" target="_blank">Quixkit</a> 2019
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->

    <!-- JS Grid Scripts Start-->
    <script>
        $(document).ready(function () {
            var db = {
                loadData: function (filter) {
                    return window.db.clients;
                },
                insertItem: function (insertingClient) {
                    window.db.clients.push(insertingClient);
                },
                updateItem: function (updatingClient) { },
                deleteItem: function (deletingClient) {
                    var clientIndex = $.inArray(deletingClient, window.db.clients);
                    window.db.clients.splice(clientIndex, 1);
                }
            };
            window.db = db;
            db.clients = [
            ];
        });
    </script>
    <script src="assets/js/lib/jsgrid/jsgrid.core.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.load-indicator.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.load-strategies.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.sort-strategies.js"></script>
    <script src="assets/js/lib/jsgrid/jsgrid.field.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.text.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.number.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.select.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.checkbox.js"></script>
    <script src="assets/js/lib/jsgrid/fields/jsgrid.field.control.js"></script>
    <script>
        $(function () {
            $("#jsGrid").jsGrid({
                height: "100%",
                width: "100%",
                filtering: false,
                editing: false,
                inserting: false,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 4,
                deleteConfirm: "真的要删除吗？",
                controller: db,
                noDataContent: "目前是空的......",
                fields: [
                    { name: "barCode", title: "商品条码", type: "text", width: 100 },
                    { name: "productName", title: "商品名称", type: "text", width: 120 },
                    { name: "timeRemain", title: "保质期剩余", type: "text", width: 50 },
                    { name: "stockAmount", title: "数量", type: "text", width: 30 },
                    { name: "stockPrice", title: "单价", type: "text", align: "right", width: 30 },
                    { type: "control" }
                ]
            });
        });
    </script>
    <!-- JS Grid Scripts End-->

</body>

</html>